import { TIMEOUT } from "./config";
import { BASE_URL } from "./config";

import axios from "axios";
import nProgress from "nprogress";
import 'nprogress/nprogress.css'
class HY_Fetch{
    constructor(baseurl,timeout){
        
        this.instance = axios.create({
            baseURL:baseurl,
            timeout:timeout
        })
        this.instance.interceptors.request.use((config)=>{
            nProgress.start()
            return config
        })
        this.instance.interceptors.response.use((res)=>{
            nProgress.done()
            return res.data;
        },()=>{
            nProgress.done()
        })
    }
    request(config){
        return this.instance(config)
    }
    get(config){
        return this.instance({
            ...config,
            method:'get'
        })
    }
    post(config){
        return this.instance({
            ...config,
            method:'post'
        })
    }
}

export default new HY_Fetch(BASE_URL,TIMEOUT);